package com.itheima70.parallaxdemo;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

import com.itheima70.parallaxdemo.ui.ParallaxListView;

public class MainActivity extends Activity {

	private ImageView parallaxImage;
	private ParallaxListView lv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		
		lv = (ParallaxListView) findViewById(R.id.lv);
		
		View mHeaderView = View.inflate(this, R.layout.layout_list_header, null);
		parallaxImage = (ImageView) mHeaderView.findViewById(R.id.iv_header);
		lv.addHeaderView(mHeaderView);
		
		// 将ImageView设置到ParallaxListView里.
		// 界面渲染结束后设置进去, 可获取高度
		parallaxImage.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
			@Override
			public void onGlobalLayout() {
				// 视图树, 界面渲染结束时被调用
				lv.setParallaxImage(parallaxImage);
				parallaxImage.getViewTreeObserver().removeGlobalOnLayoutListener(this);
			}
		});
		
		lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Cheeses.NAMES));
		
	}

}
